;--------------------------------
;Include Modern UI

  !include "MUI2.nsh"

;--------------------------------
;General

  ;Name and file
  Name "NZBScanner"
  
  OutFile "NZBScannerSetup.exe"

  BrandingText "NZBScanner"

  ;Default installation folder
  InstallDir $PROGRAMFILES\NZBScanner
  
  ;Get installation folder from registry if available
  InstallDirRegKey HKLM "Software\NZBScanner" "Install_Dir"

  ;Request application privileges for Windows Vista
  RequestExecutionLevel admin
;RequestExecutionLevel user

;--------------------------------
;Interface Settings
  !define MUI_ICON "install-icon.ico"

  !define MUI_ABORTWARNING
  !define MUI_FINISHPAGE_RUN "$INSTDIR\NZBScanner.exe"

;  !define MUI_WELCOMEFINISHPAGE_BITMAP "sidebar.bmp" 
  !define MUI_HEADERIMAGE
  !define MUI_HEADERIMAGE_BITMAP_NOSTRETCH
  !define MUI_HEADER_TRANSPARENT_TEXT
;  !define MUI_HEADERIMAGE_BITMAP "banner.bmp"
  !define MUI_LICENSEPAGE_CHECKBOX

  !define MUI_STARTMENUPAGE_REGISTRY_ROOT "HKLM" 
  !define MUI_STARTMENUPAGE_REGISTRY_KEY "Software\NZBScanner" 
  !define MUI_STARTMENUPAGE_REGISTRY_VALUENAME "StartMenuFolder"

;--------------------------------
;Pages
!insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_LICENSE "eula.txt"

Var StartMenuFolder

  !insertmacro MUI_PAGE_STARTMENU Application $StartMenuFolder



  !insertmacro MUI_PAGE_COMPONENTS
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH

  
;--------------------------------
;Languages
  !insertmacro MUI_LANGUAGE "Dutch"
;--------------------------------

Function .onInit
FindProcDLL::FindProc "NZBScanner.exe"
  StrCmp $R0 0 continueInstall
    MessageBox MB_ICONSTOP|MB_OK "De applicatie die u probeert te installeren is nog actief. Sluit deze en probeer opnieuw."
    Abort
  continueInstall:

ReadRegStr $R0 HKLM \
  "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner" \
  "UninstallString"
  StrCmp $R0 "" done
 
  MessageBox MB_OKCANCEL|MB_ICONEXCLAMATION \
  "NZBScanner is al geinstalleerd. $\n$\nKlik op 'OK' om de vorige versie te verwijderen."\
  IDOK uninst
  Abort
 
;Run the uninstaller
uninst:
  ClearErrors
  Exec $INSTDIR\uninstall.exe ; instead of the ExecWait line
done:
FunctionEnd


Function un.onInit
FindProcDLL::FindProc "NZBScanner.exe"
  StrCmp $R0 0 continueunInstall
    MessageBox MB_ICONSTOP|MB_OK "De applicatie die u probeert te deinstalleren is nog actief. Sluit deze en probeer opnieuw."
    Abort
  continueunInstall:
FunctionEnd




Section "NZBScanner" NZBScanner
  SectionIn RO

  SetOutPath "$INSTDIR"
  
  ;ADD YOUR OWN FILES HERE...
   File "NZBScanner.exe"
  
  SetOutPath "$INSTDIR\NZBScanner Libs"
   File "NZBScanner Libs\*.*"

  ;Store installation folder
   WriteRegStr HKLM SOFTWARE\NZBScanner "Install_Dir" "$INSTDIR"
  
  ;Create uninstaller
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner" "DisplayName" "NZBScanner"
   WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner" "UninstallString" '"$INSTDIR\uninstall.exe"'
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner" "NoModify" 1
   WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner" "NoRepair" 1
   WriteUninstaller "uninstall.exe"

!insertmacro MUI_STARTMENU_WRITE_BEGIN Application
 CreateDirectory    "$SMPROGRAMS\$StartMenuFolder"
 CreateShortCut     "$SMPROGRAMS\$StartMenuFolder\Uninstall.lnk" "$INSTDIR\Uninstall.exe" "" "$INSTDIR\Uninstall.exe" 0
 CreateShortCut     "$SMPROGRAMS\$StartMenuFolder\NZBScanner.lnk" "$INSTDIR\NZBScanner.exe" "" "$INSTDIR\NZBScanner.exe" 0
!insertmacro MUI_STARTMENU_WRITE_END

SectionEnd

;--------------------------------
;Descriptions

  ;Language strings
  ;LangString DESC_NZBScanner ${LANG_DUTCH} "NZBScanner"

  ;Assign language strings to sections
  !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
    !insertmacro MUI_DESCRIPTION_TEXT ${NZBScanner} "NZBScanner"
  !insertmacro MUI_FUNCTION_DESCRIPTION_END

;--------------------------------
;Uninstaller Section

Section "Uninstall"
  ;Remove registry keys
  DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\NZBScanner"
  DeleteRegKey HKLM "SOFTWARE\NZBScanner"

  ;Remove files and uninstaller
  Delete "$INSTDIR\NZBScanner Libs\*.*"
  RMDir "$INSTDIR\NZBScanner Libs\"
  Delete $INSTDIR\*.*
  delete "$INSTDIR\uninstall.exe"
  RMDir "$INSTDIR"

  ;Remove shortcuts, if any
;  !insertmacro MUI_STARTMENU_GETFOLDER Application $StartMenuFolder
  Delete "$SMPROGRAMS\NZBScanner\*.*"
  RMDir "$SMPROGRAMS\NZBScanner"

SectionEnd
